﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using DataAccess;

namespace BusinessLayer2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "UserServices" in code, svc and config file together.
    public class UserServices : IUserServices
    {

        /// <summary>
        /// Adding a new user to the database
        /// </summary>
        /// <param name="u"></param>
        public void AddUser(Common.User u)
        {
            new UserRepository().AddUser(u);
        }

        /// <summary>
        /// Updating the details of a selected user
        /// </summary>
        /// <param name="u"></param>
        public void UpdateUser(Common.User u)
        {
            new UserRepository().UpdateUser(u);
        }

        /// <summary>
        /// Getting all users that are stored in the database
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.User> GetAllUsers()
        {
            return new UserRepository().GetAllUsers();
        }

        /// <summary>
        /// Getting a User that has the same inputted username 
        /// </summary>
        /// <param name="UserName"></param>
        /// <returns></returns>
        public Common.User GetUserByUserName(string UserName)
        {
            return new UserRepository().GetUserByUserName(UserName);
        }

        /// <summary>
        /// Allow the user to login to the webiste but confirming that the username and email exists
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public bool UserLogin(string UserName, string Password)
        {
            return new UserRepository().UserLogin(UserName, Password);
        }

        /// <summary>
        /// Checking if the username already exists in the database
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public bool CheckUsernameExists(string username)
        {
            return new UserRepository().CheckUserNameExists(username);
        }

        /// <summary>
        /// Checking if the email already exists in the database
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool CheckEmailExists(string email)
        {
            return new UserRepository().CheckEmailExists(email);
        }     
        /// <summary>
        /// Getting the menu pages according to the user roles
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public IEnumerable<Common.Menu> GetMenus(int roleId)
        {
            return new MenuRepository().getMenus(roleId).AsEnumerable();
        }

        /// <summary>
        /// Getting all the roles that are linked with th=at username
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public IEnumerable<Common.Role> GetAllUserRoles(string username)
        {
            return new UserRepository().GetAllUserRoles(username);
        }
        /// <summary>
        /// Getting the menu pages according to the user roles using the username
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public IEnumerable<Common.Menu> getMenu(string username)
        {
            return new MenuRepository().getMenus(username).AsEnumerable();
        }

        /// <summary>
        /// Getting all Countries that are stored in the database
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Common.Country> GetCountries()
        {
            return new LocationRepository().GetAllCountries();
        }
    }
}
